package org.springcloud.plugin.test.config;

import org.springcloud.plugin.common.handler.RestErrorHandler;
import org.springcloud.plugin.strategy.service.interceptor.RestTemplateStrategyInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
 * @Author yanggld
 * @Date 2020/1/16-16:40
 * @Description
 */
@Configuration
public class AppConfig {
	@Bean
	@LoadBalanced
	public RestTemplate restTemplate(@Autowired(required = false) RestTemplateStrategyInterceptor restTemplateStrategyInterceptor) {
		RestTemplate restTemplate = new RestTemplate();
		if (restTemplateStrategyInterceptor != null) {
			restTemplate.getInterceptors().add(restTemplateStrategyInterceptor);
		}
		restTemplate.setErrorHandler(new RestErrorHandler());
		return restTemplate;
	}

}
